package com.lzb.newloan;

import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.lzb.newloan.utils.AlertDialog;
import com.lzb.newloan.utils.BaseActivity;

public class CommitAdviseActivity extends BaseActivity implements OnClickListener {

	private EditText content;
	private String userID;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback_);
		initView();
	}
	
	private void initView() {
		findViewById(R.id.backpress).setOnClickListener(this);
		TextView title_txt_center = (TextView) findViewById(R.id.title_txt_center);
		title_txt_center.setText("意见反馈");	
		content = (EditText) findViewById(R.id.content);
		findViewById(R.id.submit).setOnClickListener(this);
	}

	@Override
	public void processMessage(Message message) {
		switch (message.what) {
//		case Config.CODE_FEEDBACK:
//			String result = message.obj.toString();
//			try {
//				JSONObject json = new JSONObject(result);
//				int error = json.getInt("error");
//				if (error > 0) {
//					Toast.makeText(CommitAdviseActivity.this,
//							json.getString("msg"), Toast.LENGTH_SHORT).show();
//				} else {
//					Toast.makeText(CommitAdviseActivity.this, "反馈成功",
//							Toast.LENGTH_SHORT).show();
//					Intent intent = new Intent(CommitAdviseActivity.this,
//							IndexActivity.class);
//					intent.putExtra("id", 2);
//					startActivity(intent);
//					finish();
//				}
//			} catch (JSONException e) {
//				Toast.makeText(CommitAdviseActivity.this, "数据解析错误",
//						Toast.LENGTH_SHORT).show();
//				e.printStackTrace();
//			}

//			break;
		default:
			break;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.backpress:
			finish();
			break;
		case R.id.submit:
			String str = content.getText().toString();
			if (TextUtils.isEmpty(str)) {
				showDialog("请先填写意见！");
				return;
			}else {
//				if (TextUtils.isEmpty(userID)) {
					new AlertDialog(CommitAdviseActivity.this).builder().setMsg("提交成功！")
					.setNegativeButton("确定", new OnClickListener() {
						@Override
						public void onClick(View v) {
							finish();
						}
					}).show();
//				}else {
//					try {
//						HttpUtils.MydoGetAsyn(Config.FEEDBACK + "&userid=" +
//								new SharePreference(CommitAdviseActivity.this).getPrefence(Config.USER_ID)
//												+ "&content=" + URLEncoder.encode(str, "UTF-8"),Config.CODE_FEEDBACK);
//					} catch (UnsupportedEncodingException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//					}
//				}
				
			}
			break;
		default:
			break;
		}
	}

	private void showDialog(String Message) {
		// TODO Auto-generated method stub
		new AlertDialog(CommitAdviseActivity.this).builder().setMsg(Message)
				.setNegativeButton("确定", new OnClickListener() {
					@Override
					public void onClick(View v) {

					}
				}).show();
	}
	
}
